import commApi from "../api/commApi"
import dayjs from "../miniprogram_npm/dayjs/index"
export const initWxFn = function () {
  wx.$apis = commApi
  wx.$dayjs = dayjs
  // 元转分保留两位小数
  wx.$getFen = (price = 0) => {
    if (isNaN(price * 1)) {
      return 0
    }
    return Math.round(price * 100 * 100) / 100
  }
  // 分转元保留两位小数
  wx.$getYuan = (price = 0) => {
    if (isNaN(price * 1)) {
      return 0
    }
    return Math.round((price / 100) * 100) / 100
  }
  // 元转分，分转元，保留两位小数
  wx.$getPrice = (price = 0) => {
    if (isNaN(price * 1)) {
      return 0
    }
    return Math.round(price * 100) / 100
  }
  // 判断是否为空
  wx.$isNull = (val) => {
    if (val === null || val === undefined || val === "") {
      return true
    }
    return false
  }
}
